import { http } from "@/utils/request";
import type {
  pagerListQueryType,
  pagerListQueryTypeResponse,
} from "@/interface/common.ts";
import type {
  ColumnDefinedTemplateEntityRes,
  AssociateTargetTypeDto,
} from "@/interface/pm/customFieldTemplate.ts";

// 获取列表
export const getTemplateList = (
  data: pagerListQueryType,
): Promise<pagerListQueryTypeResponse<ColumnDefinedTemplateEntityRes>> => {
  return http.post("/columnDefinedTemplateEntity/list", data);
};

// 新增
export const createTemplate = (
  data: ColumnDefinedTemplateEntityRes,
): Promise<ColumnDefinedTemplateEntityRes> => {
  return http.post("/columnDefinedTemplateEntity/create", data);
};

// 编辑
export const updateTemplate = (
  data: ColumnDefinedTemplateEntityRes,
): Promise<ColumnDefinedTemplateEntityRes> => {
  return http.put("/columnDefinedTemplateEntity/edit", data);
};

// 绑定
export const associateTemplate = (
  data: AssociateTargetTypeDto,
): Promise<ColumnDefinedTemplateEntityRes> => {
  return http.post("/columnDefinedTemplateEntity/associate", data);
};

// 解绑
export const unassociateTemplate = (
  data: AssociateTargetTypeDto,
): Promise<null> => {
  return http.post("/columnDefinedTemplateEntity/unassociate", data);
};

// 查看详情
export const detailTemplate = (
  id: string,
): Promise<ColumnDefinedTemplateEntityRes> => {
  return http.get(`/columnDefinedTemplateEntity/${id}`);
};

// 删除
export const deleteTemplate = (id: string): Promise<null> => {
  return http.delete(`/columnDefinedTemplateEntity/${id}`);
};
